package com.etl.util;

import com.google.common.collect.Maps;
import com.etl.constants.CommonConstant;
import com.etl.entity.EtlBusinessDbInfo;

import java.util.Map;

/**
 * @author chaixuhong
 * @date 2020-01-07
 * @desc 提取出公共的工具方法
 */
public class CommonUtil {

    /**
     * 组装数据库信息
     *
     * @param dbInfo
     * @return
     */
    public static Map<String, String> pingDBUrlAndDriver(EtlBusinessDbInfo dbInfo) {
        String driver = "", url = "";
        Map<String,String> db = Maps.newHashMap();
        switch (dbInfo.getDbType()) {
            case "oracle": {
                driver = CommonConstant.ORACLE_DRIVER;
                url = String.format(CommonConstant.ORACLE_URL, dbInfo.getDbIp(), dbInfo.getDbPort(), dbInfo.getDbName());
                break;
            }
            case "mssql": {
                driver = CommonConstant.MSSQL_DRIVER;
                url = String.format(CommonConstant.MSSQL_URL, dbInfo.getDbIp(), dbInfo.getDbPort(), dbInfo.getDbName());
                break;
            }
            case "mysql": {
                driver = CommonConstant.MYSQL_DRIVER;
                url = String.format(CommonConstant.MYSQL_URL, dbInfo.getDbIp(), dbInfo.getDbPort(), dbInfo.getDbName());
                break;
            }
            default: {
                break;
            }
        }
        db.put("driver",driver);
        db.put("url",url);
        return db;
    }
}
